package com.ruoyi.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.DateUtils;

import com.ruoyi.system.domain.ZtfMainTables;
import com.ruoyi.system.domain.ZtfSysUserbean;

import com.ruoyi.system.domain.dto.ZtfSysUserbeanDTO;
import com.ruoyi.system.mapper.ZtfSysUserbeanMapper;

import com.ruoyi.system.result.PageResult;
import com.ruoyi.system.service.ZtfISysUserbeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户信息Service业务层处理
 * 
 * @author liupeng
 * @date 2025-06-06
 */
@Service
public class ZtfSysUserbeanServiceImpl implements ZtfISysUserbeanService
{
    @Autowired
    private ZtfSysUserbeanMapper ztfSysUserbeanMapper;

    /**
     * 查询用户信息
     * 
     * @param userId 用户信息主键
     * @return 用户信息
     */
    @Override
    public ZtfSysUserbean selectSysUserbeanByUserId(Long userId)
    {
        return ztfSysUserbeanMapper.selectSysUserbeanByUserId(userId);
    }

    /**
     * 查询用户信息列表
     * 
     * @param sysUserbean 用户信息
     * @return 用户信息
     */
    @Override
    public List<ZtfSysUserbean> selectSysUserbeanList(ZtfSysUserbean sysUserbean)
    {
        return ztfSysUserbeanMapper.selectSysUserbeanList(sysUserbean);
    }

    /**
     * 新增用户信息
     * 
     * @param sysUserbean 用户信息
     * @return 结果
     */
    @Override
    public int insertSysUserbean(ZtfSysUserbean sysUserbean)
    {

        sysUserbean.setCreateTime(DateUtils.getNowDate());
        return ztfSysUserbeanMapper.insertSysUserbean(sysUserbean);
    }

    /**
     * 修改用户信息
     * 
     * @param sysUserbean 用户信息
     * @return 结果
     */
    @Override
    public int updateSysUserbean(ZtfSysUserbean sysUserbean)
    {
        sysUserbean.setUpdateTime(DateUtils.getNowDate());
        return ztfSysUserbeanMapper.updateSysUserbean(sysUserbean);
    }

    /**
     * 批量删除用户信息
     * 
     * @param userIds 需要删除的用户信息主键
     * @return 结果
     */
    @Override
    public int deleteSysUserbeanByUserIds(Long[] userIds)
    {
        return ztfSysUserbeanMapper.deleteSysUserbeanByUserIds(userIds);
    }

    /**
     * 删除用户信息信息
     * 
     * @param userId 用户信息主键
     * @return 结果
     */
    @Override
    public int deleteSysUserbeanByUserId(Long userId)
    {
        return ztfSysUserbeanMapper.deleteSysUserbeanByUserId(userId);
    }

    /**
     * 新的用户列表
     * @param ztfSysUserbeanDTO
     * @return
     */
    @Override
    public PageResult newSelectZtSysUserbeanList(ZtfSysUserbeanDTO ztfSysUserbeanDTO) {

        PageHelper.startPage(ztfSysUserbeanDTO.getPageNum(), ztfSysUserbeanDTO.getPageSize());
        //该插件的规则 需要返回一个page对象
        Page<ZtfSysUserbean> page =  ztfSysUserbeanMapper.pageSelectZtfSysUserbean(ztfSysUserbeanDTO);

        //查询主表用于显示分页总数
//        Page<ZtfMainTables> mainTablesPage =  ztfAppMainTablesMapper.SelectByZtfMainTable();
        //调用PageHelper中的方法获取总条数和数据
        long total = page.getTotal();

        int pageNum=page.getPageNum();

        int pageSize=page.getPageSize();
        //获取用户集合
        List<ZtfSysUserbean> ztfSysUserbeanList = page.getResult();

        return new PageResult(total,ztfSysUserbeanList,pageNum,pageSize);
    }

}
